<?php namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * Class VoteResultExport
 *
 * @package App\Models
 * @property int $id
 * @property int $proposition_company_id
 * @property int $works_type_id
 * @property int $vote_award_id
 * @property string $file
 * @property string $created_at
 * @property string $updated_at
 * @property string $exported_at
 * @property-read \App\Models\VoteAward $voteAward
 * @property-read \App\Models\PropositionCompany $propositionCompany
 * @property-read \App\Models\WorksType $worksType
 * @method static \Illuminate\Database\Query\Builder|\App\Models\VoteResultExport whereId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Models\VoteResultExport wherePropositionCompanyId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Models\VoteResultExport whereWorksTypeId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Models\VoteResultExport whereVoteAwardId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Models\VoteResultExport whereFile($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Models\VoteResultExport whereCreatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Models\VoteResultExport whereUpdatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Models\VoteResultExport whereExportedAt($value)
 * @mixin \Eloquent
 */
class VoteResultExport extends Model
{
    protected $fillable = ['proposition_company_id', 'works_type_id', 'vote_award_id'];

    /**
     * 获奖奖项
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function voteAward()
    {
        return $this->belongsTo('\App\Models\VoteAward', 'vote_award_id');
    }

    /**
     * 命题企业
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function propositionCompany()
    {
        return $this->belongsTo('\App\Models\PropositionCompany', 'proposition_company_id');
    }

    /**
     * 作品类别
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function worksType()
    {
        return $this->belongsTo('\App\Models\WorksType', 'works_type_id');
    }

    /**
     * 获取文件 url
     * @return string
     */
    public function getFileUrl()
    {
        return url($this->file);
    }

    /**
     * 删除文件
     */
    public function deleteFile()
    {
        @unlink(public_path($this->file));
    }
}